% TEST_ID: LANG-EXPAND-0073
% CATEGORY: stdlib/arithmetic_ops/accumulate
% 测试 cumsum 函数

function test_cumsum

    A = 1:5;
    B = cumsum(A);

    assert_isequal(B, [1 3 6 10 15]);


    A = [1 4 7; 2 5 8; 3 6 9];

    B = cumsum(A);

    assert_isequal(B, [
        1 4 7
        3 9 15
        6 15 24
    ])

    A = [1 3 5; 2 4 6];

    B = cumsum(A, 2);

    assert_isequal(B, [
        1 4 9
        2 6 12
    ])

    A = [true false true; true true false];

    B = cumsum(A, 2);

    assert_isequal(B, [
        1 1 2
        1 2 2
    ]);

    assert_isequal(class(B), 'double');

    A = [
        9 10 3
        10 7 6
        2 1 10
    ];

    B = cumsum(A, 2, 'reverse');

    assert_isequal(B, [
        22 13 3
        23 13 6
        13 11 10
    ]);

    A = [3 5 NaN 9 0 NaN];
    B = cumsum(A);
    assert_isequal(isequaln(B, [3 8 NaN NaN NaN NaN]));


    B = cumsum(A, 'omitnan');

    assert_isequal(B, [3 8 8 17 17 17]);

    assert_isequal(isempty(cumsum([])));

    % 对空数组进行cumsum;
    A = ones(0, 3, 2);
    assert_isequal(size(cumsum(A)), [0 3 2]);
    assert_isequal(size(cumsum(A, 1)), [0 3 2]);
    assert_isequal(size(cumsum(A, 2)), [0 3 2]);
    assert_isequal(size(cumsum(A, 3)), [0 3 2]);
end

function assert_isequal(x,y)
    assert(isequal(x,y))
end